#pragma once
#include "Message.h"
#include "types.h"
#include "generic_math.h"
#include <math.h>

class CRscIirFsm
{
public:
    public:    	
	bool        Encode(CMessage *input_message, CMessage *output_message);    
	

	int32_t	GetOrigin(uint32_t stage, uint32_t actual_state, bool actual_input) {return mFromState[stage][actual_input ? 1 : 0][actual_state];};
	int32_t	GetDestination(uint32_t stage, uint32_t actual_state, bool actual_input) {return mToState[stage][actual_input ? 1 : 0][actual_state];};
	//bool		GenerateOutput(uint32_t stage, uint32_t actual_state, bool actual_input) {return mOutput[stage][actual_input ? 1 : 0][actual_state];};
    uint32_t*   GetMaxLevels(){return mMaxLevels;};
    uint32_t**   GetArriving(){return mArrivingNodes;};


    CRscIirFsm(uint32_t n, uint32_t k);
    ~CRscIirFsm();

private:
    void GenerateLevels(uint32_t length);
    bool CreateStateTransitions();
    void GenerateArriving();
    void GenerateMatrix();



private:
    
    uint32_t            mEncoderLenght;
    uint32_t            mK;

    uint32_t*           mMaxLevels;
	int32_t***			mToState;   //mToState[k][x][y] = state that machine will be if stage is k, input is x, and current state is y;
	int32_t***			mFromState; //mFromState[x][y] = state that machine was if input was x and current state is y and current stage is k;
    uint32_t**          mArrivingNodes; //number os branches that arrive at node x at stage k 

    uint32_t**          mGeneratorMatrix;
	

	friend class CBCJRLogMap;
};
